#!/bin/bash

exec 9>/tmp/fullscreen.lock
if ! flock -n 9; then
    printf 'another instance is running\n';
    exit 1
fi

bspc subscribe node_state | while read -r _ _ _ _ state flag; do
    if [ "$state" != "fullscreen" ] || [ ! -f "/tmp/eww_bar.lock" ]; then
        continue
    fi
    if [ "$flag" == on ]; then
        eww close-all
    else
        eww open bar
    fi
done
